///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// STATA code for: 
// Lehmann & Masterson(2020) "Does Aid Reduce Anti-Refugee Violence?"
// American Political Science Review
// This version: 11 May , 2020      
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// Before you run the do-file, make sure your STATA has the grc1leg package 
// installed, which is needed to replicate Figures 1 and 3. To install the 
// package, type �findit grc1leg� in your STATA command window, and then select 
// �grc1leg from http://www.stata.com/users/vwiggins� from the pop-up window.
//		  
//
//
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//																			 
//                            Table of Contents 								
//
//																	Line   
//    Create variables used in data analysis........................57
//    Replication of Table 1........................................624
//    Replication of Figure 1.......................................731
//    Replication of Figure 2.......................................770
//    Replication of Figure 3.......................................780
//    Replication of Tables and Figures in Online Appendix..........816

///////////////////////////////////////////////////////////////////////////////

// set version, directory, and load data
clear
version 13.1
set more off
set graphics off
set scheme s1mono
capture log close




*!!! replace the path below with the location where you put the unzipped 
*    replication folder !!!
gl path "C:\Users\chris\Dropbox\TRASH BIN\Final data for APSR 11 may" // <--!!replace with your location!!


cd "${path}\LehmannMastersonAPSR2020_replication"
use LehmannMastersonAPSR2020_data, clear


////////////////////////////////////////////////////////////////////////////////
//
//            Create variables used in data analysis 
//
////////////////////////////////////////////////////////////////////////////////

//// Rename key variables 

ren q3 hhid  // unique hh identifier
ren c101 hhmemb // unique hh member identifier


////1.1 Treatment dummy //// 
g treat=(elevation_oct13>=500) 
lab define lab_assign 0"control group" 1"treatment group" 
lab val treat lab_assign

////1.2 Polynomial functions //// 
g dist=elevation_oct13-500 // linear
g dist_treat=dist*treat   // linear spline
g dist2=dist^2 	          // quadratic 
g dist2_treat=dist2*treat // quadratic spline


////1.3 Violence ////
*rename and label 
ren q199 viol_syr_verb  // verbal   violence from Syrians
ren q200 viol_syr_phys  // physical violence from Syrians
ren q207 viol_leb_verb  // verbal   violence from Lebanese
ren q208 viol_leb_phys  // physical violence from Lebanese

*cleaning
foreach i of varlist viol_* {
destring `i', replace
replace `i'=. if `i'<0
}

*recoding the scale of ordinal variables
foreach i in viol_syr_verb viol_syr_phys viol_leb_verb viol_leb_phys {
g `i'_old=`i'
replace `i'=1 if `i'_old==4 // recode 'never' from 4 to 1
replace `i'=2 if `i'_old==3 // recode 'rarely' from 3 to 2
replace `i'=3 if `i'_old==2 // recode 'sometimes' from 2 to 3
replace `i'=4 if `i'_old==1 // recode 'often' from 1 to 4
drop `i'_old
}


*create dummy variable for each of the four possible answers (never, rarely, sometimes, often)
foreach i of varlist viol_* {
foreach z of numlist 1(1)4 {
g `i'_`z'=(`i'==`z') if `i'!=. 
}
}

*rename ordinal variable
foreach i in viol_syr_verb viol_syr_phys viol_leb_verb viol_leb_phys {
ren `i' `i'_ord
}

*'sometimes-or-often' dummy
foreach u in leb syr {
foreach z in verb phys {
g viol_`u'_`z'_so=(viol_`u'_`z'_3==1 | viol_`u'_`z'_4==1) if viol_`u'_`z'_ord!=.
}
}

*'rarely-or-sometimes-or-often' dummy
foreach i in syr leb {
g viol_`i'_verb_rso=(viol_`i'_verb_2==1 | viol_`i'_verb_3==1 | viol_`i'_verb_4==1) if viol_`i'_verb_ord!=.
g viol_`i'_phys_rso=(viol_`i'_phys_2==1 | viol_`i'_phys_3==1 | viol_`i'_phys_4==1) if viol_`i'_phys_ord!=.
}


*verbal-or-physical variable (used in appendix tables)
foreach i in 1 2 3 4 {
g viol_leb_verbphys_`i'=(viol_leb_verb_`i'==1|viol_leb_phys_`i'==1) if (viol_leb_verb_ord!=. | viol_leb_phys_ord!=.) 
}

g viol_leb_verbphys_ord=.
foreach i in 1 2 3 4 {
replace viol_leb_verbphys_ord=`i' if viol_leb_verbphys_`i'==1
}

*'sometimes-or-often' dummy
g viol_leb_verbphys_so=(viol_leb_phys_so==1 | viol_leb_verb_so==1) if (viol_leb_verb_ord!=. | viol_leb_phys_ord!=.)  


//// Other variables (e.g., for balance tests or descriptive statistics) ////

// Education
destring q12, replace
replace q12=. if q12<0  // don't knows and NR to missing
recode q12(0=1)         // join no school and incomplete primary
recode q12(5=4)(6=4)    // join sec/tech school and university
ren q12 educ
g educ_1=(educ==1) if educ!=.
g educ_2=(educ==2) if educ!=.
g educ_3=(educ==3) if educ!=.
g educ_4=(educ==4) if educ!=.

// age of HH head
replace q9a=. if q9a<0 
g age=2014-q9a
g age_head=.
sort hhid hhmemb
bys hhid: replace age_head=age[1] 


// # of friends and relatives in Lebanon before you came
foreach i of varlist q58 q60 {
destring `i', replace
replace `i'=. if `i'<0
}
ren q58 relatives
ren q60 friends


// month
*arrivel of HH head in Lebanon 
foreach i of varlist q11_mounth q11_year {
destring `i', replace
replace `i'=. if `i'<0
}
g a=q11_year*1000+q11_mounth   
g monthinleb=.
replace monthinleb=39 if q11_year==999 | q11_mounth==999 // in survey instrument is says: Put 999 if this household member moved to Lebanon before March 2011
replace monthinleb=39 if a==2011001
replace monthinleb=39 if a==2011002
replace monthinleb=38 if a==2011003
replace monthinleb=37 if a==2011004
replace monthinleb=36 if a==2011005
replace monthinleb=35 if a==2011006
replace monthinleb=34 if a==2011007
replace monthinleb=33 if a==2011008
replace monthinleb=32 if a==2011009
replace monthinleb=31 if a==2011010
replace monthinleb=30 if a==2011011
replace monthinleb=29 if a==2011012   
replace monthinleb=28 if a==2012001
replace monthinleb=27 if a==2012002
replace monthinleb=26 if a==2012003
replace monthinleb=25 if a==2012004
replace monthinleb=24 if a==2012005
replace monthinleb=23 if a==2012006
replace monthinleb=22 if a==2012007
replace monthinleb=21 if a==2012008
replace monthinleb=20 if a==2012009
replace monthinleb=19 if a==2012010
replace monthinleb=18 if a==2012011
replace monthinleb=17 if a==2012012
replace monthinleb=16 if a==2013001
replace monthinleb=15 if a==2013002
replace monthinleb=14 if a==2013003
replace monthinleb=13 if a==2013004
replace monthinleb=12 if a==2013005
replace monthinleb=11 if a==2013006
replace monthinleb=10 if a==2013007
replace monthinleb=9 if a==2013008
replace monthinleb=8 if a==2013009
replace monthinleb=7 if a==2013010
replace monthinleb=6 if a==2013011
replace monthinleb=5 if a==2013012
replace monthinleb=4 if a==2014001
replace monthinleb=3 if a==2014002
replace monthinleb=2 if a==2014003
replace monthinleb=1 if a==2014004
replace monthinleb=0 if a==2014005
drop a 


// Syria origin of hh head 
*In 2010, in which governorate was the permanent residence of [head of the household] in Syria?
foreach i of varlist q55 {
destring `i', replace
replace `i'=. if `i'<0
}
g origin_gov=q55
tab origin_gov if hhmemb==1 // 75% of obs in 4 govs, remaining 25% spread out across 9 govs
foreach i in 1 2 3 7 8 9 12 13 14 {
recode origin_gov(`i'=0) // recode 9 spread out govs as one category
}
g origin_gov_0=(origin_gov==0)   if origin_gov!=.  // other 
g origin_gov_4=(origin_gov==4)   if origin_gov!=.  // Dara
g origin_gov_6=(origin_gov==6)   if origin_gov!=.  // Homs
g origin_gov_10=(origin_gov==10) if origin_gov!=.  // Idleb
g origin_gov_11=(origin_gov==11) if origin_gov!=.  // Aleppo



// Consumption

*past calendar month:
ren q118_usd c_exp_tot_week 
ren q119_usd c_nf1_rent
ren q120_usd c_nf1_electricity
ren q166_usd c_nf1_calls
ren q167_usd c_nf1_internet
ren q168_usd c_nf1_tv
*since november:
ren q121_usd c_nfNOV_educ
ren q122_usd c_nfNOV_health
ren q123_usd c_nfNOV_visa
ren q124_usd c_nfNOV_docu
ren q125_usd c_nfNOV_homerepair
ren q126_usd c_nfNOV_window
ren q127_usd c_nfNOV_extwalls
ren q128_usd c_nfNOV_intwalls
ren q129_usd c_nfNOV_toilet
ren q130_usd c_nfNOV_screens
ren q131_usd c_nfNOV_door
ren q132_usd c_nfNOV_roof
ren q133_usd c_nfNOV_furniture
ren q134_usd c_nfNOV_kitchen
ren q135_usd c_nfNOV_floor
*past 30 day period: 
ren q136_1_usd c_nf30_water
ren q137_1_usd c_nf30_cleaning
ren q138_1_usd c_nf30_fuelcook
ren q139_1_usd c_nf30_fuelheat
ren q140_1_usd c_nf30_fueltransp
ren q141_1_usd c_nf30_pubtransp
ren q142_1_usd c_nf30_hygiene
ren q143_1_usd c_nf30_diapers
ren q144_1_usd c_nf30_clothing
ren q145_1_usd c_nf30_tobacco
ren q146_1_usd c_nf30_waterdrink
ren q147_1_usd c_food
*food past 7days:
*value
ren q148_3_usd c_fg_rice
ren q149_3_usd c_fg_bread
ren q151_3_usd c_fg_potat
ren q152_3_usd c_fg_milk
ren q153_3_usd c_fg_meat
ren q154_3_usd c_fg_fish
ren q156_3_usd c_fg_eggs
ren q157_3_usd c_fg_beans
ren q158_3_usd c_fg_vegs
ren q159_3_usd c_fg_fruits
ren q160_3_usd c_fg_oils
ren q161_3_usd c_fg_sweets
ren q162_3_usd c_fg_bevs
ren q163_3_usd c_fg_nuts
ren q164_3_usd c_fg_other



*cleaning
foreach i of varlist c_* {
destring `i', replace
replace `i'=. if `i'<0
}
*bring "since NOV" variables to monthly average
foreach i of varlist c_nfNOV* {
replace `i'=`i'/6
}
*bring "past 7 days" variables to monthly average
foreach i of varlist c_fg* {
replace `i'=`i'*4
}

*Monthly food consumption
egen food=rowtotal(c_fg_rice c_fg_bread c_fg_potat c_fg_milk c_fg_meat c_fg_fish c_fg_eggs c_fg_beans c_fg_vegs c_fg_fruits c_fg_oils)
replace food=food+c_nf30_fuelcook+c_nf30_water+c_nf30_waterdrink

*monthly non-food consumption
egen nfood=rowtotal(c_nf*)
replace nfood=nfood-(c_nf30_fuelcook+c_nf30_water+c_nf30_waterdrink)-c_nfNOV_homerepair 


// Debt  & savings 
ren q173_usd dl_outst_amt
ren q176_usd dl_outst_inkind_amt
ren q181_1_usd save_bank_amt
ren q185_usd save_othloc

foreach i of varlist dl_* save_*{
destring `i', replace
replace `i'=. if `i'<0
}

g dl_total=dl_outst_amt+dl_outst_inkind_amt
g save_total=save_bank_amt+save_othloc



//Labor 
ren q15 ls_dayswork
ren q17 ls_hourswork
ren q18_usd ls_income
ren q19 ls_hours_out
ren q20 ls_hours_in

*cleaning
foreach i of varlist ls* {
destring `i', replace
replace `i'=0 if `i'==.
replace `i'=. if `i'<0
}


*number of days worked...
g adult=(age>=18) if age!=.
foreach i of varlist ls* {
bys hhid: egen `i'_hh_all=sum(`i')
bys hhid adult: egen `i'_hh_byage=sum(`i')
bys hhid: egen `i'_hh_adults=max(`i'_hh_byage) // ...by adults
bys hhid: egen `i'_hh_children=min(`i'_hh_byage) // ...children
}

*daily wage per person
g ls_dayswage=ls_income_hh_all/ls_dayswork_hh_all 



// assets 
ren q92 ass_carvanpick
ren q93 ass_Motorbike 
ren q94 ass_Bicycle
ren q95 ass_Fridge
ren q96 ass_Freezer
ren q97 ass_Oven
ren q98 ass_Microwave
ren q99 ass_WashingMachine
ren q100 ass_Complapttablet
ren q101 ass_Blanket
ren q102 ass_WinterJacket
ren q103 ass_wintergloves
ren q104 ass_Winterhat
ren q105 ass_Winterpullover
ren q106 ass_Heater
ren q107 ass_HotWaterBoiler
ren q108 ass_MobilePhone
ren q109 ass_Television 
ren q110 ass_Mattresses
ren q111 ass_radio
ren q112 ass_generator
ren q113 ass_kerosenelamp
ren q114 ass_gaslamp
ren q115 ass_satellitedish
ren q116 ass_chairs
ren q117 ass_batteries

foreach i of varlist ass* {
destring `i', replace
replace `i'=. if `i'<0
}


foreach i of varlist ass_carvanpick ///
ass_Motorbike ///
ass_Bicycle ///
ass_Fridge ///
ass_Freezer ///
ass_Oven ///
ass_Microwave ///
ass_WashingMachine ///
ass_Complapttablet ///
ass_Heater ///
ass_HotWaterBoiler ///
ass_Television ///
ass_radio ///
ass_generator ///
ass_satellitedish {
ren `i' `i'_dummy
replace `i'=1 if `i'>1 & `i'!=.
} 


//Coping strategies

ren q78 cope1_food
ren q79 cope1_borrowed
ren q80 cope1_reduced
ren q81 cope1_eating
ren q82 cope1_restrict
ren q83 cope1_sent
ren q84 cope1_portion
ren q85 cope2_health
ren q86 cope2_savings
ren q87 cope2_withdrawn
ren q88 cope2_childwork
ren q89 cope2_risky
ren q90 cope2_senttown
ren q90_1 cope2_sold
ren q90_2 cope2_marriage
ren q91 cope2_strangers

*cleaning
foreach i of varlist cope* {
destring `i', replace
replace `i'=. if `i'<0
}

//Subjective wellbeing

ren q221 ps1_lifesatis 
ren q222 ps2_happy
ren q223 ps2_peace
ren q224 ps3_nerv
ren q225 ps3_down
ren q226 ps3_verydown

*cleaning
foreach i of varlist ps* {
destring `i', replace
replace `i'=. if `i'<0
}


// Provide help
ren q206 help_leb_provide

*cleaning 
foreach i of varlist help_* {
destring `i', replace
replace `i'=. if `i'<0
}

*recoding the scale
foreach i of varlist help_* {
g `i'_old=`i'
replace `i'=1 if `i'_old==4 // recode 'never' from 4 to 1
replace `i'=2 if `i'_old==3 // recode 'rarely' from 3 to 2
replace `i'=3 if `i'_old==2 // recode 'sometimes' from 2 to 3
replace `i'=4 if `i'_old==1 // recode 'often' from 1 to 4
drop `i'_old
}

*create dummy variable for each of the four possible answers (never, rarely, sometimes, often)
foreach i of numlist 1(1)4 {
g help_leb_provide_`i'=(help_leb_provide==`i') if help_leb_provide!=.
}

*'rarely-or-sometimes-or-often' dummy
g help_leb_provide_rso=(help_leb_provide_2==1 | help_leb_provide_3==1 | help_leb_provide_4==1) if help_leb_provide!=.

*'sometimes-or-often' dummy
g help_leb_provide_so=(help_leb_provide_3==1 | help_leb_provide_4==1) if help_leb_provide!=.
 

// talk
ren q204 talk_leb

*cleaning 
foreach i of varlist talk_* {
destring `i', replace
replace `i'=. if `i'<0
}

*recoding the scale
foreach i of varlist talk_* {
g `i'_old=`i'
replace `i'=1 if `i'_old==4 // recode 'never' from 4 to 1
replace `i'=2 if `i'_old==3 // recode 'rarely' from 3 to 2
replace `i'=3 if `i'_old==2 // recode 'sometimes' from 2 to 3
replace `i'=4 if `i'_old==1 // recode 'often' from 1 to 4
drop `i'_old
}

*create dummy variable for each of the four possible answers (never, rarely, sometimes, often)
foreach i of numlist 1(1)4 {
g talk_leb_`i'=(talk_leb==`i') if talk_leb!=.
}

*'rarely-or-sometimes-or-often' dummy
g talk_leb_rso=(talk_leb_2==1 | talk_leb_3==1 | talk_leb_4==1) if talk_leb!=.

*'sometimes-or-often' dummy
g talk_leb_so=(talk_leb_3==1 | talk_leb_4==1) if talk_leb!=.




// community characteristics (from own community survey)

ren p02 cc_truck
ren p03 cc_motor
ren p04 cc_distprimary
ren p05 cc_distsecondary
ren p06 cc_network 
ren p07 cc_reception
ren p08_2 cc_distclinic
ren p09_2 cc_market
ren p11 cc_distmarket
ren p14 cc_lebanese
ren p13 cc_syrians
ren p16 cc_empl_elsefarm
ren p17 cc_empl_company
ren p18 cc_empl_quarrying 
ren p19 cc_empl_resale
ren p20 cc_empl_moneylending	
ren p21 cc_empl_coal
ren p22 cc_empl_repair
ren p23 cc_empl_carpentry
ren p24 cc_empl_tailoring 
ren p25 cc_empl_transport
ren p26 cc_empl_freshmeals
ren p27 cc_empl_livestock  
ren p28 cc_empl_begging
ren p30 cc_shops
ren p31_1 cc_comehere 
ren p31_2 cc_gothere 
ren p32_usd cc_p_wint_blanket
ren p33_usd cc_p_wint_matress
ren p34_usd cc_p_wint_heater
ren p35_usd cc_p_wint_gloves
ren p36_usd cc_p_wint_coal
ren p37_usd cc_p_wint_heatoil
ren p38_usd cc_p_food_beef
ren p39_usd cc_p_food_chicken
ren p40_usd cc_p_food_fish
ren p41_usd cc_p_food_bread
ren p42_usd cc_p_food_flour
ren p43_usd cc_p_food_rice	
ren p44_usd cc_p_food_beans
ren p45_usd cc_p_food_lentil
ren p46_usd cc_p_food_peas
ren p47_usd cc_p_food_potato
ren p48_usd cc_p_food_bulgur
ren p49_usd cc_p_food_chickpeas
ren p50_usd cc_p_food_oat
ren p51_usd cc_p_food_milk
ren p52_usd cc_p_food_butter
ren p53_usd cc_p_food_choco
ren p54_usd cc_p_food_buiscuit
ren p55_usd cc_p_food_pepsi
ren p56_usd cc_p_food_orange
ren p57_usd cc_p_food_apple
ren p58_usd cc_p_food_tomato
ren p59_usd cc_p_food_waterdrink
ren p60_usd cc_p_food_egg
ren p61_usd cc_p_food_peanuts
ren p62_usd cc_p_food_nescafe
ren p63_usd cc_p_food_tea
ren p64_usd cc_p_nofood_malboro
ren p65_usd cc_p_nofood_cookoil
ren p66_usd cc_p_nofood_gas
ren p67_usd cc_p_nofood_shoes
ren p68_usd cc_p_nofood_shirt
ren p69_usd cc_p_nofood_battery
ren p70_usd cc_p_nofood_soap
ren p71_usd cc_p_nofood_toothp
ren p72_usd cc_p_nofood_deterg
ren p73_usd cc_p_nofood_diapers
ren p74_usd cc_p_nofood_watertank
ren p76_usd cc_p_nofood_aspirin
ren p77_usd cc_p_nofood_benzene
ren p78_usd cc_p_nofood_diesel
ren p79_usd cc_p_nofood_tobeirut
ren p80_usd cc_p_room
ren p81_usd cc_p_wage

foreach i of varlist cc_* {
destring `i', force replace
replace `i'=. if `i'<0
}
 
recode cc_truck(2=0)
recode cc_motor(2=0)
recode cc_network(1=0)
recode cc_network(2=0)
recode cc_network(3=1) // no/hard coverage (0) vs easy coverage (1) 



//////////////////////////////////////////////////////////////////////////////
//
//                            Replication of Table 1
//
//////////////////////////////////////////////////////////////////////////////

log using Table1, replace text

*Linear model   
*Panel I
*column 1:
xi: reg viol_leb_phys_so treat dist dist_treat   if hhmemb==1, r cluster(cas_code_apr14)
*column 2:
xi: reg viol_leb_verb_so treat dist dist_treat   if hhmemb==1, r cluster(cas_code_apr14)

*Panel II: Drop �outlier� (i.e., obs. between 490-499m)
gl dropout="(elevation_oct13<490 | elevation_oct13>=500)"
*column 1:
xi: reg viol_leb_phys_so treat dist dist_treat   if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 
*column 2:
xi: reg viol_leb_verb_so treat dist dist_treat   if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 

*Panel III: Placebo tests
*(i.) pseudo-cutoff (475m instead of 500m)
preserve
replace treat=(elevation_oct13>=475)
replace dist=elevation_oct13-475 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat			
*column 1:
xi: reg viol_leb_phys_so treat dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
*column 2:
xi: reg viol_leb_verb_so treat dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
restore

*(ii.) pseudo-cutoff (525m instead of 500m)
preserve
replace treat=(elevation_oct13>=525)
replace dist=elevation_oct13-525 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat	
*column 1:
xi: reg viol_leb_phys_so treat dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
*column 2:
xi: reg viol_leb_verb_so treat dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)	
restore

*(iii.) hostility from Syrian refugees as dep. var
*column 1:
xi: reg viol_syr_phys_so treat dist dist_treat   if hhmemb==1, r cluster(cas_code_apr14)
*column 2:
xi: reg viol_syr_verb_so treat dist dist_treat   if hhmemb==1, r cluster(cas_code_apr14)


*Quadratic model 
*Panel I
*column 3:
xi: reg viol_leb_phys_so  treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_apr14)
*column 4:
xi: reg viol_leb_verb_so  treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_apr14)

*Panel II: Drop �outlier� (i.e., obs. between 490-499m)
gl dropout="(elevation_oct13<490 | elevation_oct13>=500)"
*column 3:
xi: reg viol_leb_phys_so  treat dist dist2 dist_treat dist2_treat   if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 
*column 4:
xi: reg viol_leb_verb_so  treat dist dist2 dist_treat dist2_treat   if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 

*Panel III: Placebo tests
*(i.) pseudo-cutoff (475m instead of 500m)
preserve
replace treat=(elevation_oct13>=475)
replace dist=elevation_oct13-475 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat			
*column 3:
xi: reg viol_leb_phys_so  treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_apr14)
*column 4:
xi: reg viol_leb_verb_so  treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_apr14)
restore

*(ii.) pseudo-cutoff (525m instead of 500m)
preserve
replace treat=(elevation_oct13>=525)
replace dist=elevation_oct13-525 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat	
*column 3:
xi: reg viol_leb_phys_so  treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_apr14)
*column 4:
xi: reg viol_leb_verb_so  treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_apr14)	
restore

*(iii.) hostility from Syrian refugees as dep. var
*column 3:
xi: reg viol_syr_phys_so treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_apr14)
*column 4:
xi: reg viol_syr_verb_so treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_apr14)

log close


//////////////////////////////////////////////////////////////////////////////
//
//                            Replication of Figure 1
//
//////////////////////////////////////////////////////////////////////////////

*upper left graph
gl var="viol_leb_verb_so"
do RD_graph_linear

*upper right graph 
gl var="viol_leb_phys_so"
do RD_graph_linear

*without outlier
preserve 
keep if elevation_oct13<490 | elevation_oct13>=500
*lower left graph
ren viol_leb_verb_so viol_leb_verb_so_OUT
gl var="viol_leb_verb_so_OUT"
do RD_graph_linear

*lower right graph
ren viol_leb_phys_so viol_leb_phys_so_OUT
gl var="viol_leb_phys_so_OUT"
do RD_graph_linear
restore

grc1leg ///
viol_leb_verb_so_RDgraph_lin.gph ///
viol_leb_phys_so_RDgraph_lin.gph ///
viol_leb_verb_so_OUT_RDgraph_lin.gph ///
viol_leb_phys_so_OUT_RDgraph_lin.gph, legendfrom(viol_leb_phys_so_RDgraph_lin.gph) ///
ycom xcom span rows(2) iscale(.6)
graph save Figure1, replace
graph export Figure1.pdf, replace



//////////////////////////////////////////////////////////////////////////////
//
//                            Replication of Figure 2
//
//////////////////////////////////////////////////////////////////////////////

*This figure was created in R, please run the R script "Figure2". 



//////////////////////////////////////////////////////////////////////////////
//
//                            Replication of Figure 3
//
//////////////////////////////////////////////////////////////////////////////



gl var="food"
do RD_graph_linear

gl var="help_leb_provide_so"
do RD_graph_linear

gl var="talk_leb_so"
do RD_graph_linear

gl var="c_nf30_pubtransp"
do RD_graph_linear
 
gl var="c_nf30_fueltransp"
do RD_graph_linear

grc1leg ///
food_RDgraph_lin.gph ///
help_leb_provide_so_RDgraph_lin.gph ///
c_nf30_fueltransp_RDgraph_lin.gph ///
c_nf30_pubtransp_RDgraph_lin.gph ///
talk_leb_so_RDgraph_lin.gph, legendfrom(help_leb_provide_so_RDgraph_lin.gph) ///
com xcom span rows(3) iscale(.6)
graph save Figure3, replace
graph export Figure3.pdf, replace


*/

//////////////////////////////////////////////////////////////////////////////
//
//                            Replication of Online appendix
//
//////////////////////////////////////////////////////////////////////////////



// Table A1 //

log using Appendix_TableA1, replace text
* panel I: household characteristics 

*(i.) characteristics of of head 
su age_head month educ_1 educ_2 educ_3 educ_4 origin_gov_4 origin_gov_6 origin_gov_10 origin_gov_11 origin_gov_0 relat friends if hhmemb==1 & treat==0

*(ii.) demography
su unhcr_age18to59 unhcr_age60 unhcr_age0to4 unhcr_age5to12 unhcr_age13to17 if hhmemb==1 & treat==0
tab q9b   if hhmemb==1 & treat==0         // raction of male HH heads
tab q9b   if              treat==0        //ratio male to female HH members
tab q12a  if age>=5 & age<=17 & treat==0  // fraction of school-aged children (age 5 to 17) currently attending school 	

*(iii.) housing
g renting=(c_nf1_rent>0)
tab renting if hhmemb==1 & treat==0 // fraction renting 
drop renting
tab q77 if treat==0                 // no of rooms
tab q67 if treat==0                 // improvised shelter

*(iv.) consumption
*food
su food c_fg_bread c_fg_vegs c_fg_oils c_fg_meat c_nf30_fuelcook c_fg_milk c_fg_egg c_fg_rice c_fg_fish c_nf30_water c_fg_bean c_fg_sweet c_fg_potat c_fg_fruit c_food if hhmemb==1 & treat==0

*non-food 
su nfood c_nf1_rent c_nfNOV_health c_nf30_cleaning c_nf1_electricity c_nf30_tobacco c_nf30_pubtransp c_nf1_calls c_nf30_hygiene c_nf30_diapers c_nfNOV_educ c_nfNOV_visa c_nf30_clothing c_nf30_fuelheat c_nfNOV_homerepair c_nf30_fueltransp if hhmemb==1 & treat==0

*(v.) savings and debt
su dl_total save_total if treat==0 & hhmemb==1

*(vi.) labor supply
su ls_dayswork_hh_all      if treat==0 & hhmemb==1
su ls_dayswork_hh_adults   if treat==0 & hhmemb==1
su ls_dayswork_hh_children if treat==0 & hhmemb==1
su ls_income_hh_all        if treat==0 & hhmemb==1
tab q16

*(vii.) assets
su ass_carvanpick_dummy ass_Motorbike_dummy ass_Bicycle_dummy ass_Complapttablet_dummy ass_Television_dummy ass_radio_dummy ass_satellitedish_dummy ass_Fridge_dummy ass_Freezer_dummy ass_Oven_dummy ass_Microwave_dummy ass_WashingMachine_dummy ass_Heater_dummy ass_HotWaterBoiler_dummy ass_generator_dummy if treat==0 & hhmemb==1

su ass_MobilePhone ass_chairs ass_Blanket ass_WinterJacket ass_Winterpullover ass_Mattresses if treat==0 & hhmemb==1

*(viii.) coping strategies
su cope1_food cope1_borrowed cope1_reduced cope1_portion cope1_eating cope1_sent if treat==0 & hhmemb==1
su cope2_health cope2_savings cope2_withdrawn cope2_childwork cope2_risky cope2_senttown cope2_sold cope2_marriage cope2_strangers if treat==0 & hhmemb==1


*(ix.) hostility
su viol_leb_verb_1 viol_leb_verb_2 viol_leb_verb_3 viol_leb_verb_4 if treat==0 & hhmemb==1
su viol_leb_phys_1 viol_leb_phys_2 viol_leb_phys_3 viol_leb_phys_4 if treat==0 & hhmemb==1

*(x.) subjective well-being
su ps2_happy ps2_peace ps3_nerv ps3_down ps3_verydown ps1_lifesatis if treat==0 & hhmemb==1



* panel II: community characteristics
*(i.) demography
preserve 
keep if cas_code_oct13==cas_code_apr14
collapse (mean) cc_lebanese cc_syrians treat, by(cas_code_oct13)   
g cc_syrians_hh=cc_syrians/6
g cc_lebanese_hh=cc_lebanese/6
ttest cc_lebanese_hh, by(treat) 
ttest cc_syrians_hh if cc_syrians_hh<943.75, by(treat) // without outlier
restore 

*(ii.) geography
preserve 
keep if cas_code_oct13==cas_code_apr14
gl vars="cc_reception cc_truck cc_distclinic cc_distpri cc_distsec"
collapse (mean) $vars treat, by(cas_code_oct13)   
su $vars if treat==0 
restore

*(iv.) market for goods and services
preserve 
keep if cas_code_oct13==cas_code_apr14
gl vars="cc_market cc_distmarket cc_shops cc_comehere cc_gothere"
collapse (mean) $vars treat, by(cas_code_oct13)   
su $vars if treat==0 
restore

*(v.) prices
preserve 
keep if cas_code_oct13==cas_code_apr14
gl vars="cc_p_nofood_tobeirut cc_p_food_bread cc_p_food_milk cc_p_food_beef cc_p_food_chicken"
collapse (mean) $vars treat, by(cas_code_oct13)   
su $vars if treat==0 
restore

log close


// Table A2  //
log using Appendix_TableA2, replace text

* panel I: household characteristics 
xi: reg educ_1 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su educ_1 if hhmemb==1 & treat==0

xi: reg educ_2 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su educ_2 if hhmemb==1 & treat==0

xi: reg educ_3 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su educ_3 if hhmemb==1 & treat==0

xi: reg educ_4 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su educ_4 if hhmemb==1 & treat==0

xi: reg age_head treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su age_head if hhmemb==1 & treat==0

xi: reg relat treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su relat if hhmemb==1 & treat==0

xi: reg friends treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su friends if hhmemb==1 & treat==0

xi: reg month treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su month if hhmemb==1 & treat==0


xi: reg origin_gov_4 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su origin_gov_4 if hhmemb==1 & treat==0

xi: reg origin_gov_6 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su origin_gov_6 if hhmemb==1 & treat==0

xi: reg origin_gov_10 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su origin_gov_10 if hhmemb==1 & treat==0

xi: reg origin_gov_11  treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su origin_gov_11  if hhmemb==1 & treat==0

xi: reg origin_gov_0 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su origin_gov_0 if hhmemb==1 & treat==0


xi: reg unhcr_age0to4 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su unhcr_age0to4 if hhmemb==1 & treat==0
 
xi: reg unhcr_age5to12 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su unhcr_age5to12 if hhmemb==1 & treat==0

xi: reg unhcr_age13to17 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su unhcr_age13to17 if hhmemb==1 & treat==0

xi: reg unhcr_age18to59 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su unhcr_age18to59 if hhmemb==1 & treat==0

xi: reg unhcr_age60 treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
su unhcr_age60 if hhmemb==1 & treat==0


* panel II: community characteristics
foreach i of varlist cc_truck cc_motor cc_distpri cc_distsec cc_distclinic cc_distmarket cc_market cc_reception  {
xi: reg `i'  treat dist dist2 dist_treat dist2_treat if hhmemb==1, r cluster(cas_code_apr14)
}

preserve
keep if hhmemb==1
collapse (mean) treat dist dist2 dist_treat dist2_treat refpop_oct13, by(cas_code_oct13)
foreach i of varlist refpop_oct13 {
xi: reg `i' treat dist dist2 dist_treat dist2_treat, r
su `i' if treat==0
} 
restore


preserve
keep if hhmemb==1
sort cas_code_oct13
 collapse (mean) treat dist dist2 dist_treat dist2_treat temperature_* precipintensity_*, by(cas_code_oct13)
foreach i of varlist temperature_oct13 temperature_nov13 temperature_dec13 temperature_jan14 temperature_feb14 temperature_march14 temperature_apr14 precipintensity_oct13 precipintensity_nov13 precipintensity_dec13 precipintensity_jan14 precipintensity_feb14 precipintensity_march14 precipintensity_apr14  {
xi: reg `i' treat dist dist2 dist_treat dist2_treat, r
su `i' if treat==0
} 
restore


preserve
keep if hhmemb==1
drop if sect_maj==.
tab sect_maj
g sect_maj_sunni=(sect_maj==5)
g sect_maj_shia=(sect_maj==4)
g sect_maj_druze=(sect_maj==3)
g sect_maj_christ=(sect_maj==2)
g sect_maj_other=(sect_maj==0 | sect_maj==1 | sect_maj==6)


collapse (mean) treat dist dist2 dist_treat dist2_treat sect_maj_*, by(cas_code_oct13)
foreach i of varlist sect_maj_shia sect_maj_christ sect_maj_sunni sect_maj_druze sect_maj_other {
xi: reg `i' treat dist dist2 dist_treat dist2_treat, r
su `i' if treat==0
}
restore

log close	





//  Table A3 //
log using Appendix_TableA3, replace text

g lowskill=educ
recode lowskill(2=0)
recode lowskill(0=1)
recode lowskill(3=0)
recode lowskill(4=0)

xi: areg viol_leb_verb_rso ls_dayswork_hh_all lowskill i.origin_gov c_food nfood dl_total help_leb_provide_so if treat==0 &   hhmemb==1, absorb(cas_code_oct13) r cluster(cas_code_apr14)
xi: areg viol_leb_phys_rso ls_dayswork_hh_all lowskill i.origin_gov c_food nfood dl_total help_leb_provide_so if treat==0 &   hhmemb==1, absorb(cas_code_oct13) r cluster(cas_code_apr14)

log close



// Table A4  //
log using Appendix_TableA4, replace text

*Linear model
*Panel I
xi: reg viol_leb_phys_rso treat dist dist_treat   if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verb_rso treat dist dist_treat   if hhmemb==1, r cluster(cas_code_apr14)

*Panel II: Drop �outlier� (i.e., obs. between 490-499m)
gl dropout="(elevation_oct13<490 | elevation_oct13>=500)"
xi: reg viol_leb_phys_rso treat dist dist_treat   if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 
xi: reg viol_leb_verb_rso treat dist dist_treat   if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 

*Panel III: Placebo tests
*(i.) pseudo-cutoff (475m instead of 500m)
preserve
replace treat=(elevation_oct13>=475)
replace dist=elevation_oct13-475 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat			
xi: reg viol_leb_phys_rso treat dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verb_rso treat dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
restore

*(ii.) pseudo-cutoff (525m instead of 500m)
preserve
replace treat=(elevation_oct13>=525)
replace dist=elevation_oct13-525 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat	
xi: reg viol_leb_phys_rso treat dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verb_rso treat dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)	
restore

*(iii.) hostility from Syrian refugees as dep. var
xi: reg viol_syr_phys_rso treat dist dist_treat   if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_syr_verb_rso treat dist dist_treat   if hhmemb==1, r cluster(cas_code_apr14)

*Quadratic model
*Panel I
xi: reg viol_leb_phys_rso treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verb_rso treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_apr14)

*Panel II: Drop �outlier� (i.e., obs. between 490-499m)
gl dropout="(elevation_oct13<490 | elevation_oct13>=500)"
xi: reg viol_leb_phys_rso treat dist dist2 dist_treat dist2_treat   if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 
xi: reg viol_leb_verb_rso treat dist dist2 dist_treat dist2_treat   if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 

*Panel III: Placebo tests
*(i.) pseudo-cutoff (475m instead of 500m)
preserve
replace treat=(elevation_oct13>=475)
replace dist=elevation_oct13-475 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat			
xi: reg viol_leb_phys_rso treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verb_rso treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_apr14)
restore

*(ii.) pseudo-cutoff (525m instead of 500m)
preserve
replace treat=(elevation_oct13>=525)
replace dist=elevation_oct13-525 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat	
xi: reg viol_leb_phys_rso treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verb_rso treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_apr14)	
restore

*(iii.) hostility from Syrian refugees as dep. var
xi: reg viol_syr_phys_rso treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_syr_verb_rso treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_apr14)

log close



// Table A5 //

log using Appendix_TableA5, replace text

gl dropout="(elevation_oct13<490 | elevation_oct13>=500)"

*Linear model
*Column 1	
*Panel I
xi: reg viol_leb_phys_so treat dist dist_treat 							       if hhmemb==1, r cluster(cas_code_apr14)
*Panel II(i.)
xi: reg viol_leb_phys_so treat dist dist_treat i.origin_gov 				   if hhmemb==1, r cluster(cas_code_apr14)	
*Panel II(ii.)
xi: reg viol_leb_phys_so treat dist dist_treat i.origin_gov i.educ             if hhmemb==1, r cluster(cas_code_apr14)
*Panel II(iii.)
xi: reg viol_leb_phys_so treat dist dist_treat i.origin_gov i.educ unhcr_age*  if hhmemb==1, r cluster(cas_code_apr14)	
*Panel III
xi: reg viol_leb_phys_so treat dist dist_treat i.origin_gov i.educ unhcr_age*  if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 

*Column 2	
*Panel I
xi: reg viol_leb_verb_so treat dist dist_treat 							       if hhmemb==1, r cluster(cas_code_apr14)
*Panel II(i.)
xi: reg viol_leb_verb_so treat dist dist_treat i.origin_gov 				   if hhmemb==1, r cluster(cas_code_apr14)	
*Panel II(ii.)
xi: reg viol_leb_verb_so treat dist dist_treat i.origin_gov i.educ             if hhmemb==1, r cluster(cas_code_apr14)
*Panel II(iii.)
xi: reg viol_leb_verb_so treat dist dist_treat i.origin_gov i.educ unhcr_age*  if hhmemb==1, r cluster(cas_code_apr14)	
*Panel III
xi: reg viol_leb_verb_so treat dist dist_treat i.origin_gov i.educ unhcr_age*  if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 

*Quadratic model
*Column 3	
*Panel I
xi: reg viol_leb_phys_so treat dist dist2 dist_treat dist2_treat 							     if hhmemb==1, r cluster(cas_code_apr14)
*Panel II(i.)
xi: reg viol_leb_phys_so treat dist dist2 dist_treat dist2_treat i.origin_gov 				     if hhmemb==1, r cluster(cas_code_apr14)	
*Panel II(ii.)
xi: reg viol_leb_phys_so treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ             if hhmemb==1, r cluster(cas_code_apr14)
*Panel II(iii.)
xi: reg viol_leb_phys_so treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if hhmemb==1, r cluster(cas_code_apr14)	
*Panel III
xi: reg viol_leb_phys_so treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 

*Column 4	
*Panel I
xi: reg viol_leb_verb_so treat dist dist2 dist_treat dist2_treat 							     if hhmemb==1, r cluster(cas_code_apr14)
*Panel II(i.)
xi: reg viol_leb_verb_so treat dist dist2 dist_treat dist2_treat i.origin_gov 				     if hhmemb==1, r cluster(cas_code_apr14)	
*Panel II(ii.)
xi: reg viol_leb_verb_so treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ             if hhmemb==1, r cluster(cas_code_apr14)
*Panel II(iii.)
xi: reg viol_leb_verb_so treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if hhmemb==1, r cluster(cas_code_apr14)	
*Panel III
xi: reg viol_leb_verb_so treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if hhmemb==1 & $dropout, r cluster(cas_code_apr14) 
	
log close

	
// Table A6 //
log using Appendix_TableA6, replace text

destring elevation_apr14, replace
g movedabove=(elevation_apr14>=500 & elevation_oct13<500 & elevation_apr14!=. & elevation_oct13!=.)
tab movedabove if hhmemb==1

*linear model
xi: reg viol_leb_phys_so   treat dist dist_treat   if hhmemb==1				   , r cluster(cas_code_apr14) 
xi: reg viol_leb_phys_so   treat dist dist_treat   if hhmemb==1 & movedabove==0, r cluster(cas_code_apr14) 
xi: reg viol_leb_verb_so   treat dist dist_treat   if hhmemb==1				   , r cluster(cas_code_apr14) 
xi: reg viol_leb_verb_so   treat dist dist_treat   if hhmemb==1 & movedabove==0, r cluster(cas_code_apr14) 

*quadratic model
xi: reg viol_leb_phys_so   treat dist dist2 dist_treat dist2_treat   if hhmemb==1				 , r cluster(cas_code_apr14) 
xi: reg viol_leb_phys_so   treat dist dist2 dist_treat dist2_treat   if hhmemb==1 & movedabove==0, r cluster(cas_code_apr14) 
xi: reg viol_leb_verb_so   treat dist dist2 dist_treat dist2_treat   if hhmemb==1				 , r cluster(cas_code_apr14) 
xi: reg viol_leb_verb_so   treat dist dist2 dist_treat dist2_treat   if hhmemb==1 & movedabove==0, r cluster(cas_code_apr14) 

log close



//  Table A7 //
log using Appendix_TableA7, replace text

*Panel I.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_1 treat dist dist_treat                                 if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_1 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel I.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_1 treat dist dist2 dist_treat dist2_treat 							    if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_1 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}


*Panel II.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_2 treat dist dist_treat             				      if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_2 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel II.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_2 treat dist dist2 dist_treat dist2_treat 						        if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_2 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel III.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_3 treat dist dist_treat             				      if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_3 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel III.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_3 treat dist dist2 dist_treat dist2_treat 								if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_3 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel IV.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_4 treat dist dist_treat             			          if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_4 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel IV.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_4 treat dist dist2 dist_treat dist2_treat 							    if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_4 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

log close


// Table A8 //
log using Appendix_TableA8, replace text

preserve
keep if elevation_oct13<490 | elevation_oct13>=500

*Panel I.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_1 treat dist dist_treat             				      if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_1 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel I.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_1 treat dist dist2 dist_treat dist2_treat 					    	    if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_1 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}


*Panel II.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_2 treat dist dist_treat             				      if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_2 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel II.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_2 treat dist dist2 dist_treat dist2_treat 						        if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_2 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel III.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_3 treat dist dist_treat            				      if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_3 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel III.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_3 treat dist dist2 dist_treat dist2_treat 					    	    if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_3 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel IV.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_4 treat dist dist_treat           				      if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_4 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel IV.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg viol_leb_verbphys_4 treat dist dist2 dist_treat dist2_treat 							    if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_4 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

restore

log close





// Table A9 //
log using Appendix_TableA9, replace text

*(a) conditional correlations
* impute variables for HHs that were not selected for community survey.
foreach i of varlist cc_* {
bys cas_code_oct13: egen mu_`i'=mean(`i')
su mu_`i'
replace mu_`i'=`r(mean)' if mu_`i'==. 
}

*propensity score of outlier 
g outl=(elevation_oct13<490 | elevation_oct13>=500)
xi: reg outl i.educ age_head relat friend month i.origin_gov unhcr_age* if hhmemb==1, r cluster(cas_code_apr14)
xi: reg outl mu_cc_truck mu_cc_motor mu_cc_distpri mu_cc_distsec mu_cc_distcli mu_cc_distmar mu_cc_market mu_cc_reception refpop_oct13 if hhmemb==1, r cluster(cas_code_apr14) 


*(b)unconditional correlations 
foreach i in educ_1 educ_2 educ_3 educ_4  age_head relat friend month origin_gov_0 origin_gov_4 origin_gov_6 origin_gov_10 origin_gov_11 unhcr_age0to4 unhcr_age5to12 unhcr_age13to17 unhcr_age18to59 unhcr_age60plus {
xi: reg outl `i' if hhmemb==1,  r cluster(cas_code_apr14)
est store m_`i'
}
foreach i in mu_cc_truck mu_cc_motor mu_cc_distpri mu_cc_distsec mu_cc_distcli mu_cc_distmar mu_cc_market mu_cc_reception refpop_oct13 {
xi: reg outl `i' if hhmemb==1,  r cluster(cas_code_apr14)
est store m_`i'
}

log close



// Table A10 //
log using Appendix_TableA10, replace text

*Panel I
xi: probit viol_leb_verbphys_1 treat dist dist_treat                                 if   hhmemb==1, r cluster(cas_code_apr14)
xi: probit viol_leb_verbphys_1 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)

xi: probit viol_leb_verbphys_1 treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1, r cluster(cas_code_apr14)
xi: probit viol_leb_verbphys_1 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)

*Panel II
xi: probit viol_leb_verbphys_2 treat dist dist_treat                                 if   hhmemb==1, r cluster(cas_code_apr14)
xi: probit viol_leb_verbphys_2 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)

xi: probit viol_leb_verbphys_2 treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1, r cluster(cas_code_apr14)
xi: probit viol_leb_verbphys_2 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)

*Panel III
xi: probit viol_leb_verbphys_3 treat dist dist_treat                                 if   hhmemb==1, r cluster(cas_code_apr14)
xi: probit viol_leb_verbphys_3 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)

xi: probit viol_leb_verbphys_3 treat dist dist2 dist_treat dist2_treat 						    	   if   hhmemb==1, r cluster(cas_code_apr14)
xi: probit viol_leb_verbphys_3 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)

*Panel IV
xi: probit viol_leb_verbphys_4 treat dist dist_treat                                 if   hhmemb==1, r cluster(cas_code_apr14)
xi: probit viol_leb_verbphys_4 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)

xi: probit viol_leb_verbphys_4 treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1, r cluster(cas_code_apr14)
xi: probit viol_leb_verbphys_4 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)

log close



// Table A11 //
log using Appendix_TableA11, replace text

*Panel I
capture noisily oprobit viol_leb_verbphys_ord treat dist dist_treat                                 if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(1)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(1)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist2 dist_treat dist2_treat 								  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(1)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(1)) post

*Panel II
capture noisily oprobit viol_leb_verbphys_ord treat dist dist_treat  							    if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(2)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(2)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist2 dist_treat dist2_treat 								  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(2)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(2)) post

*Panel III
capture noisily oprobit viol_leb_verbphys_ord treat dist dist_treat                                 if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(3)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(3)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(3)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(3)) post

*Panel IV
capture noisily oprobit viol_leb_verbphys_ord treat dist dist_treat  								 if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(4)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist  dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(4)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist2 dist_treat dist2_treat 								  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(4)) post

capture noisily oprobit viol_leb_verbphys_ord treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1, r cluster(cas_code_apr14)
capture noisily margins, dydx(treat) predict(outcome(4)) post

log close








// Table A12 // 
log using Appendix_TableA12, replace text

*Linear model   
*Panel I
*column 1:
xi: reg viol_leb_phys_so treat dist dist_treat   if hhmemb==1, r cluster(cas_code_oct13)
*column 2:
xi: reg viol_leb_verb_so treat dist dist_treat   if hhmemb==1, r cluster(cas_code_oct13)

*Panel II: Drop �outlier� (i.e., obs. between 490-499m)
gl dropout="(elevation_oct13<490 | elevation_oct13>=500)"
*column 1:
xi: reg viol_leb_phys_so treat dist dist_treat   if hhmemb==1 & $dropout, r cluster(cas_code_oct13) 
*column 2:
xi: reg viol_leb_verb_so treat dist dist_treat   if hhmemb==1 & $dropout, r cluster(cas_code_oct13) 

*Panel III: Placebo tests
*(i.) pseudo-cutoff (475m instead of 500m)
preserve
replace treat=(elevation_oct13>=475)
replace dist=elevation_oct13-475 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat			
*column 1:
xi: reg viol_leb_phys_so treat dist dist_treat  if hhmemb==1, r cluster(cas_code_oct13)
*column 2:
xi: reg viol_leb_verb_so treat dist dist_treat  if hhmemb==1, r cluster(cas_code_oct13)
restore

*(ii.) pseudo-cutoff (525m instead of 500m)
preserve
replace treat=(elevation_oct13>=525)
replace dist=elevation_oct13-525 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat	
*column 1:
xi: reg viol_leb_phys_so treat dist dist_treat  if hhmemb==1, r cluster(cas_code_oct13)
*column 2:
xi: reg viol_leb_verb_so treat dist dist_treat  if hhmemb==1, r cluster(cas_code_oct13)	
restore

*(iii.) hostility from Syrian refugees as dep. var
*column 1:
xi: reg viol_syr_phys_so treat dist dist_treat   if hhmemb==1, r cluster(cas_code_oct13)
*column 2:
xi: reg viol_syr_verb_so treat dist dist_treat   if hhmemb==1, r cluster(cas_code_oct13)


*Quadratic model 
*Panel I
*column 3:
xi: reg viol_leb_phys_so  treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_oct13)
*column 4:
xi: reg viol_leb_verb_so  treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_oct13)

*Panel II: Drop �outlier� (i.e., obs. between 490-499m)
gl dropout="(elevation_oct13<490 | elevation_oct13>=500)"
*column 3:
xi: reg viol_leb_phys_so  treat dist dist2 dist_treat dist2_treat   if hhmemb==1 & $dropout, r cluster(cas_code_oct13) 
*column 4:
xi: reg viol_leb_verb_so  treat dist dist2 dist_treat dist2_treat   if hhmemb==1 & $dropout, r cluster(cas_code_oct13) 

*Panel III: Placebo tests
*(i.) pseudo-cutoff (475m instead of 500m)
preserve
replace treat=(elevation_oct13>=475)
replace dist=elevation_oct13-475 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat			
*column 3:
xi: reg viol_leb_phys_so  treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_oct13)
*column 4:
xi: reg viol_leb_verb_so  treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_oct13)
restore

*(ii.) pseudo-cutoff (525m instead of 500m)
preserve
replace treat=(elevation_oct13>=525)
replace dist=elevation_oct13-525 		
replace dist_treat=dist*treat 	
replace dist2=dist^2 	
replace dist2_treat=dist2*treat	
*column 3:
xi: reg viol_leb_phys_so  treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_oct13)
*column 4:
xi: reg viol_leb_verb_so  treat dist dist2 dist_treat dist2_treat  if hhmemb==1, r cluster(cas_code_oct13)	
restore

*(iii.) hostility from Syrian refugees as dep. var
*column 3:
xi: reg viol_syr_phys_so treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_oct13)
*column 4:
xi: reg viol_syr_verb_so treat dist dist2 dist_treat dist2_treat   if hhmemb==1, r cluster(cas_code_oct13)

log close




// Table A13 //

log using Appendix_TableA13, replace text


*Panel I: Consumption
foreach i of varlist food c_fg_bread c_fg_vegs c_fg_oils c_fg_meat c_nf30_fuelcook c_fg_milk c_fg_egg c_fg_rice c_fg_fish c_nf30_water c_fg_bean c_fg_sweet c_fg_potat c_fg_fruit c_fg_bev   {
xi: reg `i'  treat dist dist_treat i.origin_gov i.educ unhcr_age* if hhmemb==1, r cluster(cas_code_apr14)
su `i' if hhmemb==1 & treat==0
}

foreach i of varlist nfood c_nf1_rent c_nfNOV_health c_nf30_cleaning c_nf1_electricity c_nf30_tobacco c_nf30_pubtransp c_nf1_calls c_nf30_hygiene c_nf30_diapers c_nfNOV_educ c_nfNOV_visa c_nf30_clothing c_nf30_fuelheat c_nfNOV_homerepair c_nf30_fueltransp {
xi: reg `i'  treat dist dist_treat i.origin_gov i.educ unhcr_age* if hhmemb==1, r cluster(cas_code_apr14)
su `i' if hhmemb==1 & treat==0
}

*Panel II: transfers, savings, debt, labor supply
foreach i of varlist help_leb_provide_so dl_total save_total ls_dayswork_hh_all ls_income_hh_all ls_dayswage talk_leb_so {
xi: reg `i'  treat dist dist_treat i.origin_gov i.educ unhcr_age* if hhmemb==1, r cluster(cas_code_apr14)
su `i' if hhmemb==1 & treat==0
}

*Panel III: community characteristics
preserve
egen cc_p_mean=rowmean(cc_p_food* cc_p_nofood*) // price level
xi: reg cc_p_mean treat dist dist_treat if hhmemb==1, r cluster(cas_code_apr14)
su  cc_p_mean if treat==0 & hhmemb==1

xi: reg cc_p_wage treat dist dist_treat if hhmemb==1, r cluster(cas_code_apr14)
su cc_p_wage if treat==0 & hhmemb==1

foreach i of varlist cc_empl_elsefarm cc_empl_company cc_empl_quarrying cc_empl_resale cc_empl_livestock {
su `i', det
reg `i' treat dist dist_treat if hhmemb==1 & `i'<`r(p90)', r cluster(cas_code_apr14)
su `i' if treat==0 & hhmemb==1
}
restore

log close


// Table A14 //
log using Appendix_TableA14, replace text

**Food
*Panel I.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg food treat dist dist_treat                                 if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg food treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel I.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg food treat dist dist2 dist_treat dist2_treat 							    if  hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg food treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age* if  hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

**health
*Panel II.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg c_nfNOV_health treat dist dist_treat             				     if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg c_nfNOV_health treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel II.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg c_nfNOV_health treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg c_nfNOV_health treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}


**electicity
*Panel III.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg c_nf1_electricity treat dist dist_treat             			        if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg c_nf1_electricity treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel III.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg c_nf1_electricity treat dist dist2 dist_treat dist2_treat 								  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg c_nf1_electricity treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}


** Public transport
*Panel IV.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg c_nf30_pubtransp treat dist dist_treat             					   if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg c_nf30_pubtransp treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel IV.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg c_nf30_pubtransp treat dist dist2 dist_treat dist2_treat 								 if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg c_nf30_pubtransp treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}


*** Private transport
*Panel V.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg c_nf30_fueltransp treat dist dist_treat             				    if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg c_nf30_fueltransp treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel V.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg c_nf30_fueltransp treat dist dist2 dist_treat dist2_treat 								  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg c_nf30_fueltransp treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}



log close





//  Table A15 //
log using Appendix_TableA15, replace text

*Panel I.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg help_leb_provide_1 treat dist dist_treat                                 if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg help_leb_provide_1 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel I.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg help_leb_provide_1 treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg help_leb_provide_1 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}


*Panel II.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg help_leb_provide_2 treat dist dist_treat             				     if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg help_leb_provide_2 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel II.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg help_leb_provide_2 treat dist dist2 dist_treat dist2_treat 							       if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg help_leb_provide_2 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel III.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg help_leb_provide_3 treat dist dist_treat             				     if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg help_leb_provide_3 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel III.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg help_leb_provide_3 treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg help_leb_provide_3 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}


*Panel IV.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg help_leb_provide_4 treat dist dist_treat             				     if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg help_leb_provide_4 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel IV.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg help_leb_provide_4 treat dist dist2 dist_treat dist2_treat 							       if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg help_leb_provide_4 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

log close



// Table A16 //
log using Appendix_TableA16, replace text

*Panel I.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg talk_leb_1 treat dist dist_treat                                 if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg talk_leb_1 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel I.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg talk_leb_1 treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg talk_leb_1 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}


*Panel II.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg talk_leb_2 treat dist dist_treat             			         if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg talk_leb_2 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel II.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg talk_leb_2 treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg talk_leb_2 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel III.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg talk_leb_3 treat dist dist_treat             				     if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg talk_leb_3 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel III.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg talk_leb_3 treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg talk_leb_3 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}


*Panel IV.A
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg talk_leb_4 treat dist dist_treat             				     if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg talk_leb_4 treat dist dist_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

*Panel IV.B
foreach i in 0 10 20 30 40 {
loc l=450+`i'
loc u=550-`i'
di "-----------------"
di "Bandwidth=`l'-`u'"
di "-----------------"
xi: reg talk_leb_4 treat dist dist2 dist_treat dist2_treat 								   if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
xi: reg talk_leb_4 treat dist dist2 dist_treat dist2_treat i.origin_gov i.educ unhcr_age*  if   hhmemb==1 & elevation_oct13>=450+`i' & elevation_oct13<=550-`i', r cluster(cas_code_apr14)
}

log close




// Table A17 //
log using Appendix_TableA17, replace text

xi: reg viol_leb_verbphys_so i.treat*refpop_oct13     dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_so i.treat*lowskill         dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_so i.treat*unhcr_age18to59  dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_so i.treat*age_head         dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_so i.treat*relat            dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_so i.treat*friends          dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
xi: reg viol_leb_verbphys_so i.treat*month            dist dist_treat  if hhmemb==1, r cluster(cas_code_apr14)
foreach i in 4 6 10 11 0 {
xi: reg viol_leb_verbphys_so i.treat*origin_gov_`i'   dist dist_treat if hhmemb==1, r cluster(cas_code_apr14)
}

log close




//Figure A2
gl var="origin_gov_4"
do RD_graph_quadratic
gl var="origin_gov_6"
do RD_graph_quadratic
gl var="educ_4"
do RD_graph_quadratic
gl var="unhcr_age60plus"
do RD_graph_quadratic

grc1leg ///
origin_gov_4_RDgraph.gph ///
origin_gov_6_RDgraph.gph ///
educ_4_RDgraph.gph ///
unhcr_age60plus_RDgraph.gph, legendfrom(origin_gov_4_RDgraph.gph) ///
com xcom span rows(2) iscale(.6)
graph save FigureA2, replace
graph export FigureA2.pdf, replace


// Figure A3
gl var="refpop_oct13"
do RD_graph_quadratic
graph export FigureA3.pdf, replace



// erase auxiliary files 
erase viol_leb_verb_so_RDgraph_lin.gph
erase viol_leb_verb_so_OUT_RDgraph_lin.gph
erase viol_leb_phys_so_RDgraph_lin.gph
erase viol_leb_phys_so_OUT_RDgraph_lin.gph
erase talk_leb_so_RDgraph_lin.gph
erase help_leb_provide_so_RDgraph_lin.gph
erase food_RDgraph_lin.gph
erase c_nf30_pubtransp_RDgraph_lin.gph
erase c_nf30_fueltransp_RDgraph_lin.gph
erase origin_gov_4_RDgraph.gph 
erase origin_gov_6_RDgraph.gph 
erase educ_4_RDgraph.gph 
erase unhcr_age60plus_RDgraph.gph
erase refpop_oct13_RDgraph.gph
erase Figure1.gph
erase Figure3.gph
erase FigureA2.gph
erase temp_for_quadratic_graphs.dta
erase temp_for_nonparametric_graphs.dta
erase temp_bin.dta
erase nonparametric_fits.dta

sort hhid hhmemb
///////////////////////// end /////////////////////////////////////////////////
